package demo1;

import java.util.Arrays;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {
    public static void main1(String[] args) {
        int[] arr = {972,944,817,475,436,623,900,268,25,263,627,799,38,943,968,17,813,139,772,333,498,593,567,556,550,40,4,862,915,935,366,253,994,893,47,211,332,854,73,694,37,63,789,785,419,129,170,404,854,424,712,784,539,697,478,978,509,76,528,65,194,352,986,713,730,223,858,366,71,18,60,8,835,70,349,905,446,593,909,592,95,280,900,887,303,245,612,708,7,58,564,577,718,410,512,637,535,432,332,770};
        int sum = 0;
        for(int e:arr){
            sum+=e;
        }
        System.out.println(sum);
    }

    //可被三整除的最大和
    public int maxSumDivThree(int[] nums) {
        int INF = 0x3f3f3f;
        int sum = 0;
        int x1 = INF;int x2 = INF;
        int y1 = INF;int y2 = INF;
        for(int each:nums){
            sum+=each;
            if(each%3==1){
                if(each<x1){
                    x2 = x1;
                    x1 = each;
                }else if(each<x2) {
                    x2 = each;
                }
            }else if(each%3==2) {
                if (each < y1) {
                    y2 = y1;
                    y1 = each;
                } else if (each < y2) {
                    y2 = each;
                }
            }
        }
        if(sum%3==0) return sum;
        else if(sum%3==1){
            return Math.max(sum-x1,sum-y1-y2);
        }else {
            return Math.max(sum-y1,sum-x1-x2);
        }
    }

    public int maxSumDivThree1(int[] nums) {
        int n = nums.length;
        Arrays.sort(nums);
        int sum = 0;
        int x1 = Integer.MAX_VALUE;
        int x2 = Integer.MAX_VALUE;
        for(int each:nums){
            if(each%3==1) Math.min(each,x1);
            if(each%3==2) Math.min(each,x2);
            sum += each;
        }
        int key = sum%3;
        if(key==0){
            return sum;
        } else if (key == 1) {
            int cur = 0;
            for (int i = 0; i < n; i++) {
                if(nums[i]%3==2){
                    cur+=nums[i];
                }
                if(cur%3==1) break;
            }
            if(cur%3==1 && x1!=Integer.MAX_VALUE) return Math.max(sum-x1,sum-cur);
            else if(cur%3==2) return sum-cur;
        }else {
            int cur = 0;
            int min = 0;
            for (int i = 0; i < n; i++) {
                if(nums[i]%3==1){
                    cur+=nums[i];
                }
                if(cur%3==2) break;
            }
            if(cur%3==2 && x2!=Integer.MAX_VALUE) return Math.max(sum-x2,sum-cur);
            else if(cur%3==2) return sum-cur;
        }
        return 0;
    }
}











